package com.xyz.dao.gen;

import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Generator {

    @Test
    public void test(){
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        ConfigurationParser cp = new ConfigurationParser(warnings);
        try {
            org.mybatis.generator.config.Configuration config = cp.parseConfiguration(new InputStreamReader(
                    Generator.class.getResourceAsStream("/generator.xml"),"utf-8"));
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

}
